<html>
<head><meta charset="utf-8"><title>Suggest erroneous code if fix is simple? · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Suggest.20erroneous.20code.20if.20fix.20is.20simple.3F.html">Suggest erroneous code if fix is simple?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210751560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Suggest%20erroneous%20code%20if%20fix%20is%20simple%3F/near/210751560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Suggest.20erroneous.20code.20if.20fix.20is.20simple.3F.html#210751560">(Sep 21 2020 at 14:46)</a>:</h4>
<p>In this <a href="https://github.com/rust-lang/rust-clippy/issues/2944#issuecomment-680302359">comment</a> (case 1), we discuss the possibility of having Clippy suggest erroneous code (missing <code>+ '_</code>, the lint suggests removing the lifetime entirely) given that the compiler error is clear. Related PR <a href="https://github.com/rust-lang/rust-clippy/issues/5978">clippy#5978</a>.</p>
<p>I would prefer either giving the right suggestion or not linting this case, as I think Clippy should never suggest code that does not compile, but I think this is debatable and would like to have more opinions on it. </p>
<p>For the record the relevant lint does <em>not</em> support automatic fixes.</p>



<a name="210753959"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/Suggest%20erroneous%20code%20if%20fix%20is%20simple%3F/near/210753959" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/Suggest.20erroneous.20code.20if.20fix.20is.20simple.3F.html#210753959">(Sep 21 2020 at 15:02)</a>:</h4>
<p>In the PR you linked, I think the suggested solution is good: Noting that <code>'_</code> has to be inserted in some cases. (This could also be done with <code>span_lint_and_note</code>) Also putting such an example in the lint documentation is helpful.</p>
<p>As long as the lint is not auto-applicable, we should provide good enough help messages, so that the code can be improved, without producing/relying on a compiler error afterwards.</p>
<p>Not linting, just because we can't produce a perfect suggestion is not a good approach IMO.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>